package cn.operation.backend.util;

import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * API分页查询对象
 *
 * @author Jonny He
 */
public class PageVo implements Serializable {

    /**
     * @fieldName: serialVersionUID
     * @fieldType: long
     * @Description: TODO
     */
    private static final long serialVersionUID = 4289171840045697554L;
    @ApiModelProperty(value = "页码，默认是第一页",position = 0)
    private int pageNo = 1; //页码，默认是第一页
    @ApiModelProperty(value = "每页显示的记录数，默认是10",position = 1)
    private int pageSize = 10; //每页显示的记录数，默认是10
    @ApiModelProperty(value = "总记录数",position = 2)
    private int totalRecord = 0; //总记录数
    @ApiModelProperty(value = "总页数",position = 3)
    private int totalPage = 1; //总页数
    @ApiModelProperty(value = "排序",position = 4)
    private String order = ""; //排序

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalRecord() {
        return totalRecord;
    }

    public void setTotalRecord(int totalRecord) {
        this.totalRecord = totalRecord;
    }

    public int getTotalPage() {
        totalPage = totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;
        this.setTotalPage(totalPage);
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public int getStartIndex() {
        return (this.pageNo - 1) * this.pageSize;
    }

    @Override
    public String toString() {
        return "PageVo [pageNo=" + pageNo + ", pageSize=" + pageSize + ", totalRecord=" + totalRecord + ", totalPage="
                + totalPage + ", order=" + order + "]";
    }
}
